package com.taoist_awei.blog.core;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ArticleEntity {

    private String articleId;
    private String title;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    private Integer readTime;
    private String type;
    private String content;
    private String classifyId;
    private String summary;
    private String status;
    private String classifyName;
    private Integer words;

    public ArticleEntity(String title,
                         Date createTime,
                         Integer readTime,
                         String type,
                         String content,
                         String summary,
                         String classifyId,
                         String articleId,
                         Date updateTime
                         ) {
        this.articleId = articleId;
        this.title = title;
        this.createTime = createTime;
        this.readTime = readTime;
        this.type = type;
        this.summary = summary;
        this.content = content;
        this.classifyId = classifyId;
        this.updateTime = updateTime;
        this.status = ArticleStatus.DRAFT;
    }

    public void publish() {
        this.status = ArticleStatus.PUBLISH;
    }

    public ArticleEntity() { }
}
